package cn.edu.zime.tjh47;


import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class Class6_2 extends AppCompatActivity {

    Spinner major, group;
    String[][] groupData = {
            {
                    "计算2201", "计算2202",
                    "计算2301", "计算2302", "计算2303",
                    "计算2401", "计算2402", "计算2461"
            },

            {
                    "网络2201", "网络2202",
                    "网络2301", "网络2302",
                    "网络2401", "网络2402"
            },

            {
                    "大数据2201", "大数据2202",
                    "大数据2301", "大数据2302",
                    "大数据2401", "大数据2402"
            },

            {
                    "云计算2201", "云计算2202",
                    "云计算2301", "云计算2302",
                    "云计算2401"
            },

            {
                    "物联2201", "物联2202",
                    "物联2301", "物联2302", "物联2361",
                    "物联2401", "物联2402", "物联2461"
            },

            {
                    "VR2201"
            }
    };

    TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.class6_2);
        major = findViewById(R.id.major);
        group = findViewById(R.id.group);
        tv = findViewById(R.id.tv_group);
        major.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                ArrayAdapter<String> adp = new ArrayAdapter<>(Class6_2.this, android.R.layout.simple_spinner_item, groupData[i]);
                group.setAdapter(adp);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
        group.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                String str = String.format("你选择了%s%s班", major.getSelectedItem().toString(), group.getSelectedItem().toString());
                tv.setText(str);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
    }

    public void back(View view) {
        finish();
    }
}